package com.platform.service.impl;

import com.platform.dao.ShippingDao;
import com.platform.dao.WxuserOrderDao;
import com.platform.entity.WxuserOrderEntity;
import com.platform.service.WxuserOrderService;
import com.platform.utils.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("wxuserOrderService")
public class WxuserOrderServiceImpl implements WxuserOrderService {
    @Autowired
    private WxuserOrderDao orderDao;
    @Autowired
    private ShippingDao shippingDao;

    @Override
    public WxuserOrderEntity queryObject(Integer id) {
        return orderDao.queryObject(id);
    }

    @Override
    public WxuserOrderEntity queryObjectByOrderSn(String orderSn) {
        return orderDao.queryObjectByOrderSn(orderSn);
    }

    @Override
    public List<WxuserOrderEntity> queryList(Map<String, Object> map) {
        return orderDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return orderDao.queryTotal(map);
    }

    @Override
    public int save(WxuserOrderEntity order) {
        return orderDao.save(order);
    }

    @Override
    public int update(WxuserOrderEntity order) {
        return orderDao.update(order);
    }

    @Override
    public int delete(Integer id) {
        return orderDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return orderDao.deleteBatch(ids);
    }

    @Override
    public int confirm(Integer id) {
        WxuserOrderEntity orderEntity = queryObject(id);
        Integer payStatus = orderEntity.getPayStatus();//付款状态
        if (2 != payStatus) {
            throw new RRException("此订单未付款，不能确认收货！");
        }
        orderEntity.setOrderStatus(301);
        return orderDao.update(orderEntity);
    }

    @Override
    public int sendGoods(WxuserOrderEntity order) {
        Integer payStatus = order.getPayStatus();//付款状态
        if (2 != payStatus) {
            throw new RRException("此订单未付款！");
        }
        order.setOrderStatus(300);//订单已发货
        return orderDao.update(order);
    }
}
